<template>
	<view class="form_page">
		<view class="head">
			<image src="/static/image/back.png" @click="handleBack" />
			<view class="title_text">施工单位</view>
			<view class="blank"></view>
		</view>
		
		<view class="utils">
			<view class="util end edit" v-if="!isEdit" @click="handleEdit(true)">
				<image src="/static/image/edit2.png" mode=""></image> 编辑
			</view>
			<view class="util end editing" v-else>
				<image src="/static/image/edit3.png" mode=""></image> 编辑中
			</view>
		</view>
		
		<scroll-view scroll-y class="scroll">
			<form @submit="formSubmit" @reset="formReset">
				<view class="form_item">
					<view class="title_text">施工单位</view>
					<view class="my-input">
						<input v-model="buildLog.constructionUnit" :disabled="!isEdit" class="uni-input"
							name="constructionUnit" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">施工标段</view>
					<view class="my-input">
						<input v-model="buildLog.section" :disabled="!isEdit" class="uni-input"
							name="section" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">施工范围</view>
					<view class="my-input">
						<input v-model="buildLog.constructionScope" :disabled="!isEdit" class="uni-input"
							name="constructionScope" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">日期</view>
<!-- 					<view class="my-input">
						<input v-model="buildLog.date" :disabled="!isEdit" class="uni-input"
							name="date" />
					</view> -->
					<uni-datetime-picker type="date" :disabled="!isEdit" :value="buildLog.date" start="2020-3-20" end="2030-6-20"
						@change="changeDate" />
				</view>
				<view class="form_item">
					<view class="title_text">天气</view>
					<view class="my-input">
						<input v-model="buildLog.weatherCondition" :disabled="!isEdit" class="uni-input"
							name="weatherCondition" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">温度</view>
					<view class="my-input">
						<input v-model="buildLog.temperatureRange" :disabled="!isEdit" class="uni-input"
							name="temperatureRange" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">施工生产情况</view>
					<view class="my-textarea">
						<textarea v-model="buildLog.constructionProductionSituation" :disabled="!isEdit"
							name="constructionProductionSituation" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">施工进度情况</view>
					<view class="my-textarea">
						<textarea v-model="buildLog.progressArrangement" :disabled="!isEdit"
							name="progressArrangement" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">主要材料、设备进场情况</view>
					<view class="my-textarea">
						<textarea v-model="buildLog.materialEquipmentSituation" :disabled="!isEdit"
							name="materialEquipmentSituation" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">现场取样、检测情况</view>
					<view class="my-textarea">
						<textarea v-model="buildLog.samplingTestingSituation" :disabled="!isEdit"
							name="samplingTestingSituation" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">其他</view>
					<view class="my-input">
						<input v-model="buildLog.other" :disabled="!isEdit" class="uni-input"
							name="other" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">施工现场施工质量验收情况</view>
					<view class="my-input">
						<input v-model="buildLog.qualitySafetySituation" :disabled="!isEdit" class="uni-input"
							name="qualitySafetySituation" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">安全文明生产情况</view>
					<view class="my-input">
						<input v-model="buildLog.safetyProductionSituation" :disabled="!isEdit" class="uni-input"
							name="safetyProductionSituation" />
					</view>
				</view>
				<view class="form_item">
					<view class="title_text">记录人</view>
					<view class="my-input">
						<input v-model="buildLog.recorder" :disabled="!isEdit" class="uni-input"
							name="recorder" />
					</view>
				</view>
				<view class="btn" v-if="isEdit">
					<button class="cancel" type="primary" @click="handleEdit(false)">退出</button>
					<button form-type="submit" class="confirm" type="primary">保存</button>
				</view>
			</form>
		</scroll-view>
	</view>
</template>

<script>
	import request from '@/utils/request.js'
	
	export default {
		data() {
			return {
				isEdit: false,
				buildLog:{
					id:'',
					constructionUnit:'',
					section:'',
					constructionScope:'',
					date:'',
					weatherCondition:'',
					temperatureRange:'',
					constructionProductionSituation:'',
					progressArrangement:'',
					materialEquipmentSituation:'',
					samplingTestingSituation:'',
					other:'',
					qualitySafetySituation:'',
					safetyProductionSituation:'',
				}
			}
		},
		onLoad(option) {
			console.log(option, 'onLoad');
			this.id = option.id
			console.log(this.id, 'this.id')
			this.initBuild()
		},
		methods: {
			initBuild() {
				request(`/supervision/constructionLog/info?id=${this.id}`).then((res) => {
					if (res.data.code == 200) {
						console.log(res.data, 'initBuild');
						for (let key in this.buildLog) {
							// if (res.data.data[key]) {
							// }
							this.buildLog[key] = res.data.data[key]
						}
						console.log(this.buildLog, 'this.buildLog');
					}
				})
			},
			handleBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			changeDate(e){
				this.buildLog.date = e
			},
			handleEdit(isEdit) {
				this.isEdit = isEdit
			},
			formSubmit(e) {
				const inspect = e.detail.value
				console.log(this.buildLog, 'formSubmit');
				request(`/supervision/constructionLog/update`, {
					method: 'POST',
					data: this.buildLog
				}).then((res) => {
					if (res.data.code == 200) {
						uni.showToast({
							icon: 'none',
							title: '编辑成功',
							duration: 2000
						});
						this.isEdit = false
					}
					console.log(res.data, 'updateDirectory');
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "@/style/formPage.scss";
	
	.edit{
		z-index: 999;
	}
	.scroll {
		height: 80vh;
		margin-top: -30rpx;
		// background-color: #74fdff;
	}
</style>
